package com.xuan.juc.add;

import java.util.concurrent.CountDownLatch;

// 计数器
/*
* 指定线程执行完毕 再执行操作
* */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        // 总数6  必须要执行任务的时候再使用
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"go out!");
                countDownLatch.countDown(); // 数量减一
            },String.valueOf(i)).start();
        }

        countDownLatch.await(); // 等待计数器归0 然后在向下执行
        System.out.println("close door!");
    }
}
